package lxbAdmin.userSystem.controller;

import io.netty.util.internal.StringUtil;
import lxbAdmin.userSystem.common.ErrorConstants;
import lxbAdmin.userSystem.common.ResponseData;
import lxbAdmin.userSystem.dao.UserMapper;
import lxbAdmin.userSystem.dto.User;
import lxbAdmin.userSystem.entity.SystemUser;
import lxbAdmin.userSystem.server.LoginService;
import lxbAdmin.userSystem.server.SystemUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
public class LoginController {

    @Autowired
    private LoginService loginService;

    /**
     * 登陆
     *
     * @param user
     * @return
     */
    @PostMapping("/login")
    public ResponseData login(@RequestBody User user) {
        try {
            SystemUser loginUser = loginService.login(user);
            if (loginUser == null)
                return ResponseData.fail(ErrorConstants.WARN_MSG_7);
            else
                return ResponseData.loginSuccess(loginUser);
        } catch (Exception e) {
            e.printStackTrace();
            return ResponseData.fail(ErrorConstants.WARN_MSG_7);
        }
    }
}
